<template>
    <section class="wrapper">
      <myHeader :obj="myObj" @events="events"></myHeader>
      <main>
        <h2 class="editTitle_0313">填写你的行家信息，让好友为你推荐</h2>
        <div class="title_0313">个人职称</div>
        <div class="work_0313">
          <label class="label_0313">职业</label>
          <input class="workValue_0313" placeholder="预设内容" type="text" v-model.trim="occupation">
        </div>
        <div class="title_0313">行家介绍</div>
        <div class="textarea_0313">
          <textarea placeholder="内容描述" maxlength="500" v-model.trim="clarify"></textarea>
        </div>
        <div class="submit-btn">
          <myButton @sendDate="toSubmit()">提交</myButton>
        </div>
      </main>
    </section>
</template>
<script>
import wx from 'weixin-js-sdk';
import myHeader from './base/myHeader';
import myButton from './base/myButton';
import myLabel from './base/myLabel';
import hgjSkip from '../assets/js/hgjSkip';
import API from '../assets/js/fetchAPI';
import { fetch } from '../assets/api';
import { Toast } from "mint-ui";
import Client from '../assets/js/common';
export default {
  data () {
    return {
      myObj: {
        type: 3,
        text: '成为行家'
      }, 
      occupation:null,
      clarify:null,
      loginData: null,
      modify:this.$route.query.modify
    }
  },
  created(){
    hgjSkip.skip().then(res =>{
      this.loginData = res;
      let myInfo = Client.getStore('myApplyInfos');
      if(myInfo){
        this.occupation = myInfo.Job;
        this.clarify = myInfo.Introduce; 
      }
    });
  },
  methods: {
    events(i){
      if(i == 2) {
        history.back();
      }
    },
    toSubmit(){
      if(!this.occupation){
        Toast('请填写您的职业');
        return;
      }
      if(!this.clarify){
        Toast('请填写您的行家介绍');
        return;
      }
      let datas = {
          Job:this.occupation,
          Introduce:this.clarify
      };
      if(this.modify){
        this.toModify(datas).catch(err=>{
          Toast('修改失败');
        });
        return;
      }
      this.toApply(datas).catch(err=>{
        Toast(err.ErrorInfo);
      });
    },
    //提交申请成为行家信息
    async toApply(datas){
        await fetch(API.toApply,{...this.loginData[1],...datas});

        Toast('提交成功');
        this.$router.push('/recommendedUser');
    },
    //提交修改行家申请信息
    async toModify(datas){
      await fetch(API.modifyApplyInfo,{...this.loginData[1],...datas});
      Toast('修改成功');
      history.back();
    }
  },
  components: {
    myHeader,
    myButton,
    myLabel
  }
}

</script>
<style lang="less">
  .wrapper {
    width: 3.75rem;
    height: 100%;
    main {
      padding-top: .44rem;
      height: 100%;
      width: 3.75rem;
      position: absolute;
      top: 0;
      box-sizing: border-box;
      overflow-y: auto;
      .labelsWrap_0313 {
        padding: .13rem .15rem 0;
        overflow: hidden;
        margin-bottom: .4rem;
        span {
          display: block;
          float: left;
          padding: 0 .1rem;
          height: .3rem;
          line-height: .3rem;
          font-size: .14rem;
          color: #FFFFFF;
          background: #828282;
          border-radius: .04rem;
          margin: 0 .1rem .1rem 0;
        }
        .labelItem_0313 {

        }
      }
      .work_0313 {
        width: 100%;
        height: .44rem;
        padding: .1rem .15rem;
        box-sizing: border-box;
        background: white;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .label_0313 {
          font-size: .17rem;
          color: #000000;
          font-weight: 500;
        }
        .workValue_0313{
          width: 2.5rem;
          height: .24rem;
          border: none;
          font-size: .17rem;
          color: #B2B2B2;
          line-height: .24rem;
        }
      }
      .editTitle_0313 {
        font-size: .18rem;
        color: #39393D;
        padding: .15rem;
        padding-bottom: 0;
        font-weight: 500;
      }
      .title_0313 {
        padding: .21rem .16rem .1rem;
        color: #888888;
        font-size: .14rem;
      }
      .deepColor_0313 {
        font-size: .14rem;
        color: #353535;
        font-weight: 500;
      }
      .textarea_0313 {
        width: 3.75rem;
        min-height: .75rem;
        background: white;
        padding: .11rem .15rem;
        box-sizing: border-box;
        textarea {
          width:100%;
          font-size: .17rem;
          color:#B2B2B2;
          min-height: 2rem;
        }
      }
      .submit-btn{
        padding:.2rem 0;
      }
    }

  }
</style>
